package com.lemon.smartsafety.ui.fragment.safe.data;

import com.ldzs.recyclerlibrary.Mode;
import com.lemon.smartsafety.app.AppManager;
import com.lemon.smartsafety.app.AppService;
import com.lemon.smartsafety.app.BundleKey;
import com.lemon.smartsafety.app.EventTag;
import com.lemon.smartsafety.entity.common.CommonVoEx;
import com.lemon.smartsafety.entity.common.SelectDataI;
import com.lemon.smartsafety.entity.event.common.SelectItemEvent;
import com.lemon.smartsafety.entity.safe.company.CompanyBuildingItemCountVo;
import com.lemon.smartsafety.http.service.SafeDataServices;
import com.lemon.smartsafety.listener.RecyclerTClickListener;
import com.lemon.smartsafety.ui.activity.safe.data.BuildingBaseCheckItemListActivity;
import com.lemon.smartsafety.ui.adapter.common.SelectAdapter;
import com.lemon.smartsafetynew.ui.fragment.base.BasePullToRefreshFragment;
import com.lemon.smartsafety.utils.common.LoggerHelper;
import com.lemon.smartsafety.utils.common.StringUtils;

import java.util.List;

import kale.adapter.LemonRcvAdapter;

/**
 * 检查项目 基础数据
 */
public class BuildingBaseCheckItemListFragment extends BasePullToRefreshFragment<SelectDataI, List<CommonVoEx>> implements RecyclerTClickListener<SelectDataI> {
    private LoggerHelper loggerHelper = new LoggerHelper(BuildingBaseCheckItemListFragment.class);
    /**
     * bundle info
     */
    private CompanyBuildingItemCountVo mCompanyBuildingItemCountVo;

    public static BuildingBaseCheckItemListFragment newInstance() {
        return new BuildingBaseCheckItemListFragment();
    }


    private String mOldValue = "";
    private String mKeyWord  = "";

    @Override
    protected void getBaseArguments() {
        super.getBaseArguments();
        if (getArguments() != null) {
            mOldValue = StringUtils.nullValue(getArguments().getString(BundleKey.OLD_SELECT_VALUE));
            mKeyWord = StringUtils.nullValue(getArguments().getString(BundleKey.KEY_WORD));
            mCompanyBuildingItemCountVo = (CompanyBuildingItemCountVo) getArguments().getSerializable(BundleKey.COMPANY_BUILDING_ITEM_COUNT);
        }

    }

    @Override
    protected void initViews() {
        super.initViews();
        pageSize = Integer.MAX_VALUE;//这样设置一下，就不就有加载更多了
        mPullToRefreshRecyclerView.setRefreshMode(Mode.PULL_FROM_START);
    }


    @Override
    public boolean goRefreshOnCreate() {
        return true;
    }

    @Override
    public LemonRcvAdapter<SelectDataI> getLemonAdapter() {
        return new SelectAdapter(mDataList, this, mOldValue, true);
    }

    @Override
    public String getHttpTag() {
        return EventTag.TAG_SAFE_DATA_COLLECTION_BUILDING_BASE_CHECK_ITEM_LIST;
    }

    @Override
    public void onItemClick(SelectDataI data, int position) {
        SelectItemEvent event = new SelectItemEvent();
        event.setTag(BuildingBaseCheckItemListFragment.class.getName());
        event.setData(data);
        AppService.getBus().post(event);
        AppManager.getAppManager().finishActivity(BuildingBaseCheckItemListActivity.class);
    }

    @Override
    public void onLoadMore() {

    }


    @Override
    public void onPullRefresh() {
        SafeDataServices.init().getBaseCheckItemList(mCompanyBuildingItemCountVo.getBuildingId(), mCompanyBuildingItemCountVo.getFloorNumber(), mCompanyBuildingItemCountVo.getPositionMark(), mKeyWord);
    }

}
